package com.haoting.mamba.team.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haoting.common.utils.Query;
import com.haoting.mamba.team.entity.TeamAdvancedEntity;
import com.haoting.mamba.team.entity.vo.ZhanJI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoting.mamba.team.entity.TeamBasicdateEntity;
import com.haoting.mamba.team.service.TeamBasicdateService;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.R;



/**
 * 
 *
 * @author tanghao
 * @email 767417609@qq.com
 * @date 2021-03-14 21:09:05
 */
@RestController
@RequestMapping("team/teambasicdate")
public class TeamBasicdateController {
    @Autowired
    private TeamBasicdateService teamBasicdateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teamBasicdateService.queryPage(params);

        return R.ok().put("page", page);
    }
    @GetMapping("/infobyteamId/{id}")
    public R infobyteamId(@PathVariable("id") String id){
        TeamBasicdateEntity one = teamBasicdateService.getOne(new QueryWrapper<TeamBasicdateEntity>().eq("team_Id", id));

        return R.ok().put("teambasic", one);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		TeamBasicdateEntity teamBasicdate = teamBasicdateService.getById(id);

        return R.ok().put("teamBasicdate", teamBasicdate);
    }

    @GetMapping("/getTeamId/{id}")
    public R getPlayerId(@PathVariable("id") String id){
        TeamBasicdateEntity basicdateEntity = teamBasicdateService.getById(id);
        return R.ok().put("teamId",basicdateEntity.getTeamId());
    }

    @GetMapping("/xizhanji")
    public R xizhanji(){

        List<ZhanJI> xizhanji = teamBasicdateService.xizhanji();
        for (int i = 1; i <= xizhanji.size(); i++) {
            xizhanji.get(i-1).setSort(i);
        }
        return R.ok().put("xizhanji",xizhanji);
    }
    @GetMapping("/dongzhanji")
    public R dongzhanji(){
        List<ZhanJI> dongzhanji = teamBasicdateService.dongzhanji();
        for (int i = 1; i <= dongzhanji.size(); i++) {
            dongzhanji.get(i-1).setSort(i);
        }
        return R.ok().put("dongzhanji",dongzhanji);
    }
    @PostMapping("/infoByTeamId/{id}")
    public R infoByPlayerId(@PathVariable("id") String id){
        QueryWrapper<TeamBasicdateEntity> wrapper =new QueryWrapper<>();
        wrapper.eq("team_id",id)
                .eq("stage",0);
        TeamBasicdateEntity one = teamBasicdateService.getOne(wrapper);
        return R.ok().put("teamBasicdate", one);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TeamBasicdateEntity teamBasicdate){
		teamBasicdateService.save(teamBasicdate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TeamBasicdateEntity teamBasicdate){
		teamBasicdateService.updateById(teamBasicdate);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		teamBasicdateService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
